//
//  CartoonReadingCollectionViewCell.m
//  Cartoon
//
//  Created by dllo on 15/11/2.
//  Copyright © 2015年 YSZ. All rights reserved.
//

#import "CartoonReadingCollectionViewCell.h"

@implementation CartoonReadingCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.myScrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
        self.myImageView = [[UIImageView alloc] initWithFrame:self.bounds];
        _myScrollView.delegate = self;
        _myScrollView.minimumZoomScale = 1;
        _myScrollView.maximumZoomScale = 4;
        _myImageView.userInteractionEnabled = YES;
        _myScrollView.userInteractionEnabled = YES;
        [self.contentView addSubview:_myScrollView];
        [self.myScrollView addSubview:_myImageView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAciton:)];
        tap.numberOfTapsRequired = 1;
        tap.numberOfTouchesRequired = 1;
        [_myScrollView addGestureRecognizer:tap];
    }
    return self;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    // 指定一个scrollView的子视图,跟着scrollview一起缩放
    // 一旦进行了缩放操作,scrollView 的 contentSize 就和这个方法指定的 view 的 frame.size 一样大,确保能使用 scrollView 滚动查看这个 View 的所有内容
    
    return [scrollView.subviews firstObject];
}


- (void)tapAciton:(UIGestureRecognizer *)tap
{
    CGPoint point = [tap locationInView:self.myScrollView];
    NSLog(@"scroller %f,%f",point.x,point.y);
    [self.delegate passValue:tap point:point];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    _myScrollView.zoomScale = 1.0;
    self.myScrollView.frame = self.bounds;
    self.myImageView.frame = self.bounds;
}
@end
